import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class FormWindow extends JFrame {

	private JMenuBar menu = null;
	private JMenu menuFichier = null;
	private JMenuItem menuFichierOpen = null;

	private JLabel checking_status = null;
	private JLabel credit_history = null;
	private JLabel savings_status = null;
	private JLabel housing = null;
	private JLabel other_payment_plans = null;
	private JLabel purpose = null;
	private JLabel foreign_worker = null;
	private JLabel empty = null;

	private JComboBox jc_checking_status = null;
	private JComboBox jc_credit_history = null;
	private JComboBox jc_savings_status = null;
	private JComboBox jc_housing = null;
	private JComboBox jc_other_payment_plans = null;
	private JComboBox jc_purpose = null;
	private JComboBox jc_foreign_worker = null;

	private JPanel borderPanel = null;
	private JPanel gridPanel = null;

	private JButton valider = null;

	private final DefaultListCellRenderer dlcr = new DefaultListCellRenderer();

	public JLabel getChecking_status() {
		return checking_status;
	}

	public void setChecking_status(JLabel checking_status) {
		this.checking_status = checking_status;
	}

	public JLabel getCredit_history() {
		return credit_history;
	}

	public void setCredit_history(JLabel credit_history) {
		this.credit_history = credit_history;
	}

	public JLabel getSavings_status() {
		return savings_status;
	}

	public void setSavings_status(JLabel savings_status) {
		this.savings_status = savings_status;
	}

	public JLabel getHousing() {
		return housing;
	}

	public void setHousing(JLabel housing) {
		this.housing = housing;
	}

	public JLabel getOther_payment_plans() {
		return other_payment_plans;
	}

	public void setOther_payment_plans(JLabel other_payment_plans) {
		this.other_payment_plans = other_payment_plans;
	}

	public JLabel getPurpose() {
		return purpose;
	}

	public void setPurpose(JLabel purpose) {
		this.purpose = purpose;
	}

	public JLabel getForeign_worker() {
		return foreign_worker;
	}

	public void setForeign_worker(JLabel foreign_worker) {
		this.foreign_worker = foreign_worker;
	}

	public void setValider(JButton valider) {
		this.valider = valider;
	}

	public JMenu getMenuFichier() {
		return menuFichier;
	}

	public void setMenuFichier(JMenu menuFichier) {
		this.menuFichier = menuFichier;
	}

	public JMenuItem getMenuFichierOpen() {
		return menuFichierOpen;
	}

	public void setMenuFichierOpen(JMenuItem menuFichierOpen) {
		this.menuFichierOpen = menuFichierOpen;
	}

	public void setMenu(JMenuBar menu) {
		this.menu = menu;
	}

	JLabel getEmpty() {
		return empty;
	}

	public void setEmpty(JLabel empty) {
		this.empty = empty;
	}

	public FormWindow() {
		super();
		initialize();
	}

	private void initialize() {
		this.setSize(500, 300);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.setJMenuBar(getMenu());
		borderPanel = new JPanel();
		borderPanel.add(getPanel(), BorderLayout.CENTER);
		this.setContentPane(borderPanel);
		this.setTitle("TP CREDIT");
		this.setVisible(true);
	}

	private JMenuBar getMenu() {
		if (menu == null) {
			menu = new JMenuBar();
			menuFichier = new JMenu();

			// Ajout du menu Fichier dans la barre de menu
			menuFichier.setText("Fichier");
			menuFichier.setOpaque(false);

			// Ajout du sous-menu ouvrir dans le menu Fichier
			menuFichierOpen = new JMenuItem();
			menuFichierOpen.setText("Ouvrir...");
			menuFichierOpen.setActionCommand("Ouvrir");
			// menuFichierOpen.addActionListener(new MainWindowListener(this));
			menuFichier.add(menuFichierOpen);
			menu.add(menuFichier);
		}
		return menu;
	}

	private JButton getValider() {
		if (valider == null) {
			valider = new JButton();
			valider.setText("Valider");
			valider.setActionCommand("Valider");
			// valider.addActionListener(new MainWindowListener(this));
		}
		return valider;
	}

	private JPanel getPanel() {
		if (gridPanel == null) {
			gridPanel = new JPanel();
			gridPanel.setLayout(new GridLayout(8, 2));

			checking_status = new JLabel("Checking status");
			credit_history = new JLabel("Credit history");
			savings_status = new JLabel("Savings status");
			housing = new JLabel("Housing");
			other_payment_plans = new JLabel("Other payment plans");
			purpose = new JLabel("Purpose");
			foreign_worker = new JLabel("Foreign worker");
			empty = new JLabel();

			gridPanel.add(checking_status);
			gridPanel.add(get_jc_checking_status());

			gridPanel.add(credit_history);
			gridPanel.add(get_jc_credit_history());

			gridPanel.add(savings_status);
			gridPanel.add(get_jc_savings_status());

			gridPanel.add(housing);
			gridPanel.add(get_jc_housing());

			gridPanel.add(other_payment_plans);
			gridPanel.add(get_jc_other_payment_plans());

			gridPanel.add(purpose);
			gridPanel.add(get_jc_purpose());

			gridPanel.add(foreign_worker);
			gridPanel.add(get_jc_foreign_worker());

			gridPanel.add(empty);
			gridPanel.add(getValider());

		}
		return gridPanel;
	}

	public JComboBox get_jc_checking_status() {
		dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
		if (jc_checking_status == null) {
			jc_checking_status = new JComboBox();
			jc_checking_status.addItem("<0");
			jc_checking_status.addItem("0<=X<200");
			jc_checking_status.addItem(">=200");
			jc_checking_status.addItem("no checking");
			jc_checking_status.setPreferredSize(new Dimension(200,
					jc_checking_status.getHeight()));
		}
		jc_checking_status.setRenderer(dlcr);
		return jc_checking_status;
	}

	public JComboBox get_jc_credit_history() {
		dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
		if (jc_credit_history == null) {
			jc_credit_history = new JComboBox();
			jc_credit_history.addItem("no credits/all paid");
			jc_credit_history.addItem("all paid");
			jc_credit_history.addItem("existing paid");
			jc_credit_history.addItem("delayed previously");
			jc_credit_history.addItem("critical/other existing credit");
			jc_credit_history.setPreferredSize(new Dimension(200,
					jc_credit_history.getHeight()));
		}
		jc_credit_history.setRenderer(dlcr);
		return jc_credit_history;
	}

	public JComboBox get_jc_savings_status() {
		dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
		if (jc_savings_status == null) {
			jc_savings_status = new JComboBox();
			jc_savings_status.addItem("<100");
			jc_savings_status.addItem("100<=X<500");
			jc_savings_status.addItem("500<=X<1000");
			jc_savings_status.addItem(">=1000");
			jc_savings_status.addItem("no known savings");
			jc_savings_status.setPreferredSize(new Dimension(200,
					jc_savings_status.getHeight()));
		}
		jc_savings_status.setRenderer(dlcr);
		return jc_savings_status;
	}

	public JComboBox get_jc_housing() {
		dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
		if (jc_housing == null) {
			jc_housing = new JComboBox();
			jc_housing.addItem("rent");
			jc_housing.addItem("own");
			jc_housing.addItem("for free");
			jc_housing.setPreferredSize(new Dimension(200, jc_housing
					.getHeight()));
		}
		jc_housing.setRenderer(dlcr);
		return jc_housing;
	}

	public JComboBox get_jc_other_payment_plans() {
		dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
		if (jc_other_payment_plans == null) {
			jc_other_payment_plans = new JComboBox();
			jc_other_payment_plans.addItem("bank");
			jc_other_payment_plans.addItem("stores");
			jc_other_payment_plans.addItem("none");
			jc_other_payment_plans.setPreferredSize(new Dimension(200,
					jc_other_payment_plans.getHeight()));
		}
		jc_other_payment_plans.setRenderer(dlcr);
		return jc_other_payment_plans;
	}

	public JComboBox get_jc_purpose() {
		dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
		if (jc_purpose == null) {
			jc_purpose = new JComboBox();
			jc_purpose.addItem("new car");
			jc_purpose.addItem("used car");
			jc_purpose.addItem("furniture/equipment");
			jc_purpose.addItem("radio/tv");
			jc_purpose.addItem("domestic appliance");
			jc_purpose.addItem("repairs");
			jc_purpose.addItem("education");
			jc_purpose.addItem("vacation");
			jc_purpose.addItem("retraining");
			jc_purpose.addItem("business");
			jc_purpose.addItem("other");
			jc_purpose.setPreferredSize(new Dimension(200, jc_purpose
					.getHeight()));
		}
		jc_purpose.setRenderer(dlcr);
		return jc_purpose;
	}

	public JComboBox get_jc_foreign_worker() {
		dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
		if (jc_foreign_worker == null) {
			jc_foreign_worker = new JComboBox();
			jc_foreign_worker.addItem("yes");
			jc_foreign_worker.addItem("no");
			jc_foreign_worker.setPreferredSize(new Dimension(200,
					jc_foreign_worker.getHeight()));
		}
		jc_foreign_worker.setRenderer(dlcr);
		return jc_foreign_worker;
	}

	public static void main(String[] args) {
		FormWindow fw = new FormWindow();
	}
}
